<?php
namespace Android\Model;


class ClassManagerModel extends BaseModel {

    /**
     * 根据老师id,查询该老师所管理的所有班级id
     *
     * @param $tid
     * @return array
     */
    public function getClassIdsByTid($tid) {

        $map['teacher_id'] = $tid;
        $res = $this->where($map)->find();
        if (empty($res)) return null;

        $ids = explode(',',$res['class_id']);
        if (empty($ids)) return null;

        return $ids;
    }



    public function getClassManagerIdByTid($tid) {
        return $this->where('teacher_id = ' .$tid)->getField('id');
    }


    /**
     * 根据班级ID,查询该班级的教师ID
     *
     * @param $cid
     * @param $did 系别ID,非必要。辅助字段,减少查询数据库操作
     * @return int | array
     */
    public function getTidByCid($cid,$did=null) {

        $map = null;
        !is_null($did) && $map['department_id'] = $did;
        is_null($map) && $map = '';
        $res = $this->where($map)->select();

        foreach ($res as $k=>$v) {
            $arr = explode(',',$v['class_id']);
            if (in_array($cid,$arr)) {
                return $v['teacher_id'];
            }
        }

        return false;
    }


}